package com.wh.service.impl;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wh.dao.DeptDao;
import com.wh.entity.PageResult;
import com.wh.pojo.Dept;
import com.wh.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = DeptService.class)
@Transactional
public class DeptServiceImpl implements DeptService {

    @Autowired
    private DeptDao deptDao;

    @Override
    public void save(Dept dept) {

    }

    @Override
    public List<Dept> findAll() {
        return deptDao.findAll();
    }

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        //分页助手
        PageHelper.startPage(currentPage,pageSize);
        Page<Dept> page = deptDao.selectByCondition(queryString);
        //构建机返回值
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void add(Dept dept) {
        deptDao.add(dept);
    }

    @Override
    public void edit(Dept dept) {
        deptDao.edit(dept);
    }

    @Override
    public Dept findById(Integer id) {
        return deptDao.findById(id);
    }

    @Override
    public void deleteById(Integer id) {
        deptDao.deleteById(id);
    }
}
